﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using IndexMarkSilverlightClient.IndexMarkServiceReference;
using System.ComponentModel;

namespace IndexMarkSilverlightClient.Views
{
    public partial class OrderedVolums : ChildWindow, INotifyPropertyChanged
    {
        private IndexMarkServiceClient client = new IndexMarkServiceClient();
        
        public OrderedVolums()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(OrderedVolums_Loaded);
        }

        void OrderedVolums_Loaded(object sender, RoutedEventArgs e)
        {
            client.GetOrderedVolumsCompleted += new EventHandler<GetOrderedVolumsCompletedEventArgs>(client_GetOrderedVolumsCompleted);
            client.GetOrderedVolumsAsync(this.IDCharGrad);
            
            VolumsGrid.Visibility = System.Windows.Visibility.Collapsed;
            CharTB.Visibility = Visibility.Collapsed;
            GradTB.Visibility = Visibility.Collapsed;
        }

        void client_GetOrderedVolumsCompleted(object sender, GetOrderedVolumsCompletedEventArgs e)
        {
            Volums = e.Result;

            int i = 1;
            foreach (VolumePPS VPPS in Volums)
            {
                VPPS.Order = i;
                i++;
            }

            VolumsGrid.ItemsSource = Volums;
            CharTB.Text = this.Characteristic;
            GradTB.Text = this.Gradation;

            VolumsGrid.Visibility = System.Windows.Visibility.Visible;
            CharTB.Visibility = Visibility.Visible;
            GradTB.Visibility = Visibility.Visible;
            loadingBar.Visibility = System.Windows.Visibility.Collapsed;
        }

        public int IDCharGrad { get; set; }

        private ObservableCollection<VolumePPS> volums = new ObservableCollection<VolumePPS>();

        private String characteristic;

        public String Characteristic
        {
            get 
            {
                return characteristic; 
            }
            set
            {
                characteristic = value;
            }
        }

        private String gradation;

        public String Gradation
        {
            get
            {
                return gradation;
            }
            set
            {
                gradation = value;
            }
        } 

        public ObservableCollection<VolumePPS> Volums
        {
            get 
            {
                return volums; 
            }
            set
            {
                volums = value; 
            }
        }

        

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        public event PropertyChangedEventHandler PropertyChanged;


    }
}

